import greenfoot.*;
import java.util.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Clase Medusa here.
 * 
 * @author Andrés Cruz Santiago ,Jesús Aurelio Hrnández Aguilar
 * @version 04/07/13
 */
public class Medusa extends Estatico
{
    private GreenfootImage []imagenes;
    private java.util.List detect;
    private Heroe hr;
    /**
     * Act - do whatever the Medusa wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public Medusa(Heroe bola)
    {
        imagenes=new GreenfootImage[2];
        imagenes[0]=new GreenfootImage("medusa1.png");
        imagenes[1]=new GreenfootImage("medusa2.png");
        hr=bola;
    }

    public void act() 
    {  
        World mundo=this.getWorld();
        int band;
        band=busca();
        BalaMedusa bala;

        switch(band)
        {
            case 1://Derecha
           
            setImage(imagenes[1]);
            bala=new BalaMedusa(1);
            mundo.addObject(bala,getX(),getY());
            break;
            case 2://Abajo
           
            setImage(imagenes[1]);
            bala=new BalaMedusa(2);
            mundo.addObject(bala,getX(),getY()+20);
            break;
            case 3://Izquierda
           
            setImage(imagenes[1]);
            bala=new BalaMedusa(3);
            mundo.addObject(bala,getX(),getY());
            break;
            case 4://Arriba
           
            setImage(imagenes[1]);
            bala=new BalaMedusa(3);
            mundo.addObject(bala,getX(),getY());
            break;
        }

    }

    public int busca()
    {
        int Dir=0;
        int Grados;
        turnTowards(hr.getX(),hr.getY());
        Grados=this.getRotation();
        if(Grados==0 || Grados==1 || Grados==3 || Grados==5)
        {
            Dir=1;//Derecha
        }
        else
            setImage(imagenes[0]);
        if(Grados==90 ||Grados==87 || Grados==93 || Grados==95)
        {
            Dir=2;//Abajo
        }
        else
            setImage(imagenes[0]);
        if(Grados==180 ||Grados==183 || Grados==178)
        {           
            Dir=3;//Izquierda
        }
        else
            setImage(imagenes[0]);
        if(Grados==270 || Grados==265)
        {
            Dir=4;//Arriba
        }
        else
            setImage(imagenes[0]);
        if(Grados==356 || Grados==357 || Grados==358 || Grados==359)
        {
            Dir=1;
        }
        else
            setImage(imagenes[0]);
        return Dir;
    }
}  